package org.example.adservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.example.adservice.mapper.AdCategoryMapper;
import org.example.adservice.service.AdCategoryService;
import org.example.pojo.AdCategory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 广告分类服务实现类
 */
@Service
@RequiredArgsConstructor
public class AdCategoryServiceImpl implements AdCategoryService {

    private final AdCategoryMapper adCategoryMapper;

    @Override
    public AdCategory createCategory(AdCategory category) {
        adCategoryMapper.insert(category);
        return category;
    }

    @Override
    public AdCategory updateCategory(Integer id, AdCategory category) {
        category.setId(id);
        adCategoryMapper.updateById(category);
        return category;
    }

    @Override
    public boolean deleteCategory(Integer id) {
        return adCategoryMapper.deleteById(id) > 0;
    }

    @Override
    public AdCategory getCategoryById(Integer id) {
        return adCategoryMapper.selectById(id);
    }

    @Override
    public List<AdCategory> getAllCategories() {
        return adCategoryMapper.selectList(new QueryWrapper<>());
    }
}